package com.job.springSea.work0715;

import java.util.Arrays;

/**
 * @author 于春海
 * @version 1.0
 * @since 2022-07-15 14:45:17
 */
public class StringConstructor {
    public static void main(String[] args) {
        byte[] bytes={97,98,99,100,101,102};
        String s1=new String(bytes); //按照默认字符集  unicode 来转换字节整数的码值到字符
        System.out.println(s1);

        String s2=new String(bytes,1 , 3);
        System.out.println(s2);

        char[] chars={'A','我',66,'!','=','他'};
        System.out.println(new String(chars));
        String s3=new String(chars,3,3);
        System.out.println(s3);

        //字符串到字节 字符数组
        String name="夏日一个雪糕";//UTF-8 下 一个汉字字节 使用 3个字节表示
        byte[] nameBytes=name.getBytes();
        System.out.println(Arrays.toString(nameBytes));

        char[] chars1=name.toCharArray();
        System.out.println(Arrays.toString(chars1));

        //------------
        char c=name.charAt(3);//指定下标处的字符  从0开始
        System.out.println(c);
        //长度,字符个数
        System.out.println(name.length());
        for (int i = 0; i <name.length() ; i++) {
            System.out.println(i+"="+name.charAt(i));
        }
        //求字符串里的大写字母个数
        String str="public class StringConstructor";

        int count=0;
        for (int i = 0; i <str.length() ; i++) {
            if(Character.isUpperCase(str.charAt(i))){//要么比较码值 65:A
                count++;
            }
        }
        System.out.println(count);
    }
}